package com.mycompany.app.testsuite.webservice;

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.mycompany.app.common.webservice.mock.IBankingService;
import com.mycompany.app.testsuite.BaseTestUtils;

public class WebServiceClientTest extends BaseTestUtils {
    public static void main(String[] args) throws MalformedURLException, Exception {

        /**
         * method  1
         */
        Client client = new Client(new URL(
                "http://localhost:9090/services/IBankingService?wsdl"));

        Object[] results = client.invoke("transferFunds", new Object[] {
                "guoxu1231", "shawn.guo", new Double(1.2), "RMB" });

        System.out.println(results[0]);

        /**
         * method 2
         */
        Service serviceModel = new ObjectServiceFactory()
                .create(IBankingService.class);
        IBankingService service = (IBankingService) new XFireProxyFactory()
                .create(serviceModel,
                        "http://localhost:9090/services/IBankingService");
        System.out.println(service.transferFunds("guoxu", "shawn.guo", 1.6,
                "RMB"));

    }

}
